import Vue from "vue";
import VueRouter from "vue-router";
import Loading from "../views/Loading.vue";
import Index from "../views/Index.vue";
import Tang from "../views/Tang.vue";
import Song from "../views/Song.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "load",
    component: Loading,
  },
  {
    path: "/index",
    component: Index,
  },
  {
    path: "/tang",
    component: Tang,
  },
  {
    path: "/song",
    component: Song,
  },
];

const router = new VueRouter({
  routes,
});

//全局路由守卫 应用场景：后台管理系统，必须登录才能跳转到主页面
// router.beforeEach((to, from, next) => {
//   console.log(to)
//   console.log(from)
//   const tokenStr = localStorage.getItem('token')
//   if (to.path === '/home' && !tokenStr) {
//     next('/login')
//   } else {
//     next()
//   }
// })
export default router;
